package com.kuizii.base.common.configs;


import com.kuizii.base.common.idgenerator.BaseGenerator;
import com.kuizii.base.common.idgenerator.SnowFlakeGenerator;
import com.kuizii.base.common.idgenerator.UUIDGenerator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.format.DateTimeFormatter;

/**
 * @Author: nuanyang
 * @Date: 2019/8/16 0016 11:22
 */

@Configuration(proxyBeanMethods = false)
public class IdGeneratorConfig {

    @ConditionalOnMissingBean
    @Bean
    BaseGenerator baseGenerator(){
        BaseGenerator baseGenerator=new BaseGenerator();
        baseGenerator.setNodeId(1);
        baseGenerator.setDateTimeFormatter(DateTimeFormatter.ofPattern("yyMMddHHmmss"));
        return baseGenerator;
    }

    @ConditionalOnMissingBean
    @Bean
    SnowFlakeGenerator snowFlakeGenerator(){
        SnowFlakeGenerator baseGenerator=new SnowFlakeGenerator();
        baseGenerator.setNodeId(1);
        return baseGenerator;
    }

    @Bean
    public UUIDGenerator uuidGenerator() {

        return new UUIDGenerator();
    }
}
